<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>文件管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="layui/css/layui.css">
	</head>
	<body>

		<div class="layui-layout layui-layout-admin">
			<form class="layui-form">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">sftp服务器</label>
						<div class="layui-input-inline">
							<select id="sftp" name="id" lay-filter="sftp">
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit="" lay-filter="sftp">立即提交</button>
					</div>
				</div>
			</form>
		</div>

		<script src="layui/layui.js" charset="utf-8"></script>
		<script>
			layui.config({
				base: 'js/', //静态资源所在路径
			}).extend({
				index: 'http', //主入口模块
			}).use(['table', 'dropdown', 'jquery', 'http', 'form'], function() {
				var table = layui.table;
				var dropdown = layui.dropdown;
				var $ = layui.jquery;
				var api = layui.http.api;
				var form = layui.form;

				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
				//提交表单
				form.on('submit(sftp)', function(data) {
					parent.$('#sftpId').val(data.field.id)
					parent.layer.close(index);
				});

				$.ajax({
					type: 'POST',
					url: api + 'sftp/getAll',
					dataType: 'json',
					success: function(result) {
						if (result.code == 0) {
							var length = result.data.length;
							if (length > 0) {
								var list = result.data;
								let option = '';
								for (var i = 0; i < list.length; i++) {
									var sftp = list[i];
									option = option.concat('<option value="' + sftp['id'] + '">' + sftp[
											'host'] + '-->' + sftp['userName'] +
										'</option>')
								}
								$('#sftp').append(option);
								form.render();
							};
						} else {
							layer.msg('加载sftp服务器列表失败', {
								icon: 5
							});
						}
					},
					error: function(result) {
						layer.msg('网络异常,加载sftp服务器列表失败,稍后重试', {
							icon: 5
						});
					}
				});

			});
		</script>

	</body>
</html>
